package chapter21;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * @program: exercise
 * @description: 测试map集合
 * @author: 陈庆彪
 * @create: 2020-02-24 09:37
 **/
public class TestMap {
    public static void main(String[] args) {
        Map<String,Integer> hashMap=new HashMap<>();
        hashMap.put("Smith",30);
        hashMap.put("Anderson",31);
        hashMap.put("Lewis",29);
        hashMap.put("Cook",29);
        System.out.println("Display entries in HashMap");
        System.out.println(hashMap+"\n");

        //创建treeMap
        Map<String,Integer> treeMap=new TreeMap<>(hashMap);
        System.out.println("Display entries in treeMap");
        System.out.println(treeMap+"\n");

        //创建LinkedHashMap
        Map<String,Integer> linkedHashMap=new LinkedHashMap<>(16,0.75f,true);
        linkedHashMap.put("Smith",30);
        linkedHashMap.put("Anderson",31);
        linkedHashMap.put("Lewis",29);
        linkedHashMap.put("Cook",29);
        System.out.println("\nThe age for"+"Lewis is"+linkedHashMap.get("Lewis"));
        System.out.println("Display entries in linkedHashMap");
        System.out.println(linkedHashMap);



    }
}
